package com.kyp.basic;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableUtils;

public class BasicCalcKey implements WritableComparable<BasicCalcKey>{
	
	private String groupColumnKey;
	private Integer columnIndex;
	

	public BasicCalcKey(){
		
	}
	
	public BasicCalcKey(String groupCol, Integer colIndex){
		this.groupColumnKey = groupCol;
		this.columnIndex = colIndex;
	}
	
	public String getGroupColumnKey() {
		return groupColumnKey;
	}

	public void setGroupColumnKey(String groupColumnKey) {
		this.groupColumnKey = groupColumnKey;
	}

	public Integer getColumnIndex() {
		return columnIndex;
	}

	public void setColumnIndex(Integer columnIndex) {
		this.columnIndex = columnIndex;
	}
	
	@Override
	public String toString() {
		return (new StringBuilder()).append(groupColumnKey).append(",").append(columnIndex)
				.toString();
	}
	@Override
	public void readFields(DataInput in) throws IOException {
		groupColumnKey = WritableUtils.readString(in); 
		columnIndex = in.readInt();
	}

	@Override
	public void write(DataOutput out) throws IOException {
		WritableUtils.writeString(out, groupColumnKey);
		out.writeInt(columnIndex);
		
	}

	@Override
	public int compareTo(BasicCalcKey o) {
		int result = groupColumnKey.compareTo(o.groupColumnKey);
		if(result == 0) result = columnIndex.compareTo(o.columnIndex);
		
		return result;
	}


}
